package com.vibration.web.controller.baseinfo;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vibration.common.annotation.Log;
import com.vibration.common.core.controller.BaseController;
import com.vibration.common.core.domain.AjaxResult;
import com.vibration.common.enums.BusinessType;
import com.vibration.baseinfo.domain.CzCalculateTx;
import com.vibration.baseinfo.service.ICzCalculateTxService;
import com.vibration.common.utils.poi.ExcelUtil;
import com.vibration.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * Tx计算记录Controller
 * 
 * @author Mr_Wu
 * @date 2023-03-07
 */
@RestController
@RequestMapping("/baseinfo/calculateTx")
public class CzCalculateTxController extends BaseController
{
    @Autowired
    private ICzCalculateTxService czCalculateTxService;

    /**
     * 查询Tx计算记录列表
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:calculateTx:list')")
    @GetMapping("/list")
    public TableDataInfo list(CzCalculateTx czCalculateTx)
    {
        startPage();
        List<CzCalculateTx> list = czCalculateTxService.selectCzCalculateTxList(czCalculateTx);
        return getDataTable(list);
    }

    /**
     * 导出Tx计算记录列表
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:calculateTx:export')")
    @Log(title = "Tx计算记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CzCalculateTx czCalculateTx)
    {
        List<CzCalculateTx> list = czCalculateTxService.selectCzCalculateTxList(czCalculateTx);
        ExcelUtil<CzCalculateTx> util = new ExcelUtil<CzCalculateTx>(CzCalculateTx.class);
        util.exportExcel(response, list, "Tx计算记录数据");
    }

    /**
     * 获取Tx计算记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:calculateTx:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(czCalculateTxService.selectCzCalculateTxById(id));
    }

    /**
     * 新增Tx计算记录
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:calculateTx:add')")
    @Log(title = "Tx计算记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CzCalculateTx czCalculateTx)
    {
        czCalculateTx.setCalcType(0);
        czCalculateTx.setCreateBy(getLoginUser().getUser().getNickName());
        return toAjax(czCalculateTxService.insertCzCalculateTx(czCalculateTx));
    }

    /**
     * 新增Excel计算记录
     */
    @PostMapping("/TxExcelCompute")
    public AjaxResult TxExcelCompute(@RequestBody CzCalculateTx czCalculateTx)
    {
        return AjaxResult.success(czCalculateTxService.insertCzCalculateTxExcelCompute(czCalculateTx));
    }


    /**
     * 新增导入Excel导入计算
     */
    @PostMapping("/importData")
    public AjaxResult importTxData(MultipartFile file, CzCalculateTx czCalculateTx) throws Exception
    {
        String setfileName=file.getOriginalFilename().substring(0,file.getOriginalFilename().lastIndexOf("."));
        czCalculateTx.setCalcType(1);
        czCalculateTx.setCreateBy(getLoginUser().getUser().getNickName());
        czCalculateTx.setCalculateTitle(setfileName);
        CzCalculateTx CalculateTx = czCalculateTxService.importExcelData(file,czCalculateTx);
        return AjaxResult.success(CalculateTx);
    }


    /**
     * 修改Tx计算记录
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:calculateTx:edit')")
    @Log(title = "Tx计算记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CzCalculateTx czCalculateTx)
    {
        return toAjax(czCalculateTxService.updateCzCalculateTx(czCalculateTx));
    }

    /**
     * 删除Tx计算记录
     */
    @PreAuthorize("@ss.hasPermi('baseinfo:calculateTx:remove')")
    @Log(title = "Tx计算记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(czCalculateTxService.deleteCzCalculateTxByIds(ids));
    }
}
